using System;
using HCP.Responses;
using HCP.SimpleJSON;
using UnityEngine;

namespace HCP.Requests
{
	public class ElementReflection : JobRequest
	{
		public ElementReflection(JSONClass json) : base(json)
		{
		}

		public string Id
		{
			get
			{
				return base.Data["elementId"];
			}
		}

		public string Name
		{
			get
			{
				return base.Data["name"];
			}
		}

		public ElementReflection.ETarget Target
		{
			get
			{
				JSONNode d = base.Data["type"];
				string text = d;
				if (text != null)
				{
					if (text == "property")
					{
						return ElementReflection.ETarget.PROPERTY;
					}
					if (text == "method0")
					{
						return ElementReflection.ETarget.METHOD0;
					}
				}
				throw new FormatException("Unsupported element request");
			}
		}

		public override JobResponse Process()
		{
			string value = null;
			Component elementById = JobRequest.GetElementById(this.Id);
			ElementReflection.ETarget target = this.Target;
			if (target != ElementReflection.ETarget.PROPERTY)
			{
				if (target == ElementReflection.ETarget.METHOD0)
				{
					value = Element.ReflectMethod0(elementById, this.Name);
				}
			}
			else
			{
				value = Element.ReflectProperty(elementById, this.Name);
			}
			return new StringResponse(value);
		}

		public enum ETarget
		{
			PROPERTY,
			METHOD0
		}
	}
}
